<template>
	<div class="wrap">
		<div class="h">{{option}}</div>
		<rich-text :nodes="rich" style="font-size: 26rpx;"></rich-text>
	</div>
</template>
<script>
	// import cjSlider from '@/components/jxs-slider/jxs-slider.vue'
	import config from '../../config.js';
	export default {
		// components: {
		// 	cjSlider
		// },
		data() {
			return {
				radius: false,
				code: '',
				option: '',
				rich: ''
			}
		},
		onLoad(option) {
			let that = this

			if (option.id == 0) {
				// 用户协议
				this.option = '用户协议'
			} else {
				// 隐私协议
				this.option = '隐私协议'
			}
			let data = {
				title: this.option
			}
			this.api.get('neirong/agreement/app/listAll', data).then(res => {
				console.log(res.data.data.agreement)
				if (res.data.code == 200) {
					this.rich = res.data.data.agreement
					this.formatRichText(this.rich)
				} else {
					uni.showToast({
						title: res.data.msg,
						icon: 'none',
						duration: 1500
					});
				}
			})

		},

		onReady() {

		},

		onShow() {},

		onShareAppMessage(res) { //发送给朋友
			return {
				title: '逸居盛京',
				path: '/pages/home/index',
				imageUrl: "",
			}
		},
		onShareTimeline(res) { //分享到朋友圈
			return {
				title: '逸居盛京',
				path: '/pages/home/index',
				imageUrl: "",
			}
		},
		methods: {
			formatRichText(html) {
				//控制小程序中图片大小
				let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
					console.log(match.search(/style=/gi));
					if (match.search(/style=/gi) == -1) {
						match = match.replace(/\<img/gi, '<img style=""');
					}
					return match;
				});

				newContent = newContent.replace(/style="/gi, '$& max-width:100% !important; ');
				newContent = newContent.replace(/<br[^>]*\/>/gi, '');
				//过滤pre标签
				newContent = newContent.replace(/<(\/)?pre[^>]*>/gi, '');
				this.newContent = newContent
				return newContent;
			},
		}
	}
</script>


<style lang="scss">
	page {
		width: 750rpx;
		height: 100%;
		background-color: #f9f9f9;
		box-sizing: border-box;
	}

	.wrap {
		width: 650rpx;
		height: 100vh;
		margin: 0 auto;
	}

	.h {
		font-size: 38rpx;
		font-weight: bold;
		text-align: center;
		width: 100%;
		margin: 0 auto 50rpx;
	}
</style>